/*
 * @Author: chunlai
 * @Date: 2025-07-17 14:16:34
 * @LastEditTime: 2025-07-24 16:24:07
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @FilePath: \02.bldinsure\src\mixins\radios.js
 * @Description: 按钮类操作
 */
export const radioMixin = {
  methods: {
    changeMsRadio(type, item) {
      if (type == "sex") {
        if (["0", "3", "20"].includes(this.userInfo.idType)) return;
      } else if (type == "validDateEnd") {
        let val = "";
        if (item.value) {
          val = this.$store.state.dictionary.longTime;
        }
        this.changeData({
          validDateEnd: val,
        });
        return;
      }
      let data = {};
      data[type] = item.value;
      this.changeData(data);
    },
    changeRadioInfo(obj, key) {
      let data = {};
      const keyId = obj.keyId !== undefined ? obj.keyId : obj.value;
      const text = obj.text !== undefined ? obj.text : obj.label;
      switch (key) {
        case "degree":
          data.degree = keyId;
          data.degreeName = text;
          break;
        case "maritalStatus":
          data.maritalStatus = keyId;
          data.maritalStatusName = text;
          break;
        case "otherCompanyCompIns":
          data.otherCompanyCompIns = keyId;
          break;
        default:
          console.warn(`Unknown key: ${key}`);
          return;
      }
      this.changeData(data);
    },
    // 通讯地址同居住地
    setPostalToJuZhu(value) {
      const umsg = this.userInfo;
      if (!umsg.areaName) return;
      let obj = {
        postalPermanentAddress: value ? umsg.permanentAddress : "", // 详细地址
        postalAreaName: value ? umsg.areaName : "", // 省市区
        postalProvince: value ? umsg.province : "",
        postalProvinceName: value ? umsg.provinceName || "" : "",
        postalCity: value ? umsg.city : "",
        postalCityName: value ? umsg.cityName || "" : "",
        postalCounty: value ? umsg.county : "",
        postalCountyName: value ? umsg.countyName || "" : "",
      };
      if (this.infoReg.postalTown !== void 0 && umsg.town) {
        obj.postalTown = value ? umsg.town : "";
        obj.postalTownName = value ? umsg.townName : "";
      }
      if (this.infoReg.postalZipCode !== void 0 && umsg.zipCode) {
        obj.postalZipCode = value ? umsg.zipCode : "";
      }
      this.changeData(obj);
      this.postSameHome = value;
    },
    // 家庭地址同通讯地址
    setHomeToPostal(value) {
      const umsg = this.userInfo;
      if (!umsg.postalAreaName) return;
      let obj = {
        homePermanentAddress: value ? umsg.postalPermanentAddress : "", // 详细地址
        homeAreaName: value ? umsg.postalAreaName : "", // 省市区
        homeProvince: value ? umsg.postalProvince : "",
        homeProvinceName: value ? umsg.postalProvinceName || "" : "",
        homeCity: value ? umsg.postalCity : "",
        homeCityName: value ? umsg.postalCityName || "" : "",
        homeCounty: value ? umsg.postalCounty : "",
        homeCountyName: value ? umsg.postalCountyName || "" : "",
      };
      if (this.infoReg.homeTown !== void 0 && umsg.postalTown) {
        obj.homeTown = value ? umsg.postalTown : "";
        obj.homeTownName = value ? umsg.postalTownName : "";
      }
      this.changeData(obj);
      this.homeSamePostal = value;
    },
    handleFile(objVal, uType) {
      this.showFile = false;
      if (objVal === false) {
        return false;
      }
      this.userInfo.taxIdentInfo = objVal;
      if (objVal.crsIdType) {
        this.userInfo.crsIdType = objVal.crsIdType;
        this.userInfo.crsIdTypeName = objVal.crsIdTypeName;
      }
    },
  },
};
